package com.icss.library.service.impl;

import com.icss.library.dao.BookMapper;
import com.icss.library.exception.BizException;
import com.icss.library.pojo.Book;
import com.icss.library.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.object.SqlCall;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookMapper bookMapper;

    @Override
    @Transactional(readOnly = true)
    public List<Book> list(String bname) {
        return bookMapper.list(bname);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int addBook(Book book) {
        try {
            bookMapper.addBook(book);
            bookMapper.addBook(book);
            return 1;
        } catch (Exception e) {
            throw e;
        }
    }

    @Override
    @Transactional
    public int updateBook(Book book) {
        return bookMapper.updateBook(book);
    }

    @Override
    @Transactional
    public int delBook(Integer bookId) {
        return bookMapper.delBook(bookId);
    }
}
